﻿using FC.ERP.TMom.Api.AppHandlers.Commands.EssentialDatas.FactoryManages.Workstations;
using FC.ERP.TMom.Api.DTOs;
using FC.ERP.TMom.Domain;
using FC.ERP.TMom.ErrorCode;
using FC.ERP.TMom.Infrastructure.Interfaces;
using MediatR;

namespace FC.ERP.TMom.Api.AppHandlers.CommandHandlers.EssentialDatas.FactoryManages.Workstations
{
    public class ProcessOperationQuertyCommandHandler : IRequestHandler<ProcessOperationQuertyCommand, APIResult<List<ProcessOperationDTO>>>
    {
        private readonly IBaseRepository<ProcessOperation> processrepository;
        public ProcessOperationQuertyCommandHandler(IBaseRepository<ProcessOperation> processrepository)
        {
            this.processrepository = processrepository;
        }
        public Task<APIResult<List<ProcessOperationDTO>>> Handle(ProcessOperationQuertyCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ProcessOperationDTO>> result = new APIResult<List<ProcessOperationDTO>>();
            result.Code=ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();
            var list = from a in processrepository.GetAll()
                       select new ProcessOperationDTO
                       {
                           ProcessOperationId = a.ProcessOperationId,
                           ProcessOperationName = a.ProcessOperationName
                       };
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
